<style lang="less">
    @import "loanAnalyze.less";
</style>
<template>
    <div class="loanAnalyze"  style="background-color: #0C25F1">
        <Collapse v-model="values">
            <Panel name="1">
                留言
                <div slot="content" >
                    <Row >
                        <Table border  :columns="remindColums" :data="remindList">
                            <template slot-scope="{ row, index }" slot="action">
                                <a v-if="row.cancel" @click="cancelRemind(row)">撤销</a>
                            </template>
                            <template slot-scope="{ row, index }" slot="remindType">
                                <span>{{setDictTitleByType("msgType",row.remindType)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="remindContent">
                                <span>{{setDictTitleByType("msgType",row.remindContent)}}</span>
                            </template>
                        </Table>
                    </Row>
                </div>
            </Panel>
            <Panel name="2">
                客户概况
                <div slot="content"  >
                    <Row style="margin-left: 30px">
                        <Col >
                            车型:&nbsp&nbsp<Input type="text" style="width: 200px" v-model="custInfo.modelName" disabled >
                            </Input>
                            首付比例:&nbsp&nbsp<Input type="text" style="width: 80px" v-model="custInfo.downPayScale" disabled >
                            </Input>%
                            贷款期限:&nbsp&nbsp<Input type="text" style="width: 80px" v-model="custInfo.loanTerms" disabled >
                            </Input>
                            贷款金额:&nbsp&nbsp<Input type="text" style="width: 80px" v-model="custInfo.loanAmt" disabled>
                            </Input>
                            累加贷款金额:&nbsp&nbsp<Input type="text" style="width: 80px" v-model="custInfo.totalLoanAmt" disabled placeholder="请输入">
                            </Input>
                        </Col>

                    </Row>
                    <br/>
                    <Row style="background-color: #fadb14">
                        <Table  width="100%" border  :columns="custInfoColums" :data="custInfo.custInfoList">
                            <template slot-scope="{ row, index }" slot="custRelation">
                                <span>{{setDictTitleByType("custRelation",row.custRelation)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="sex">
                                <span>{{setDictTitleByType("sex",row.sex)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="maritalStatus">
                                <span>{{setDictTitleByType("maritalStatus",row.maritalStatus)}}</span>
                            </template>
                        </Table>
                    </Row>
                </div>
            </Panel>
            <Panel class="creditCardBox" name="3">
                信贷选项
                <div slot="content">
                    <Row v-for="option in creditOptions" class="creditRow" >
                        <RadioGroup v-model="option.riskContent" :name="option.parameterName" class="radioGroup"
                                    @on-change="afterRadioChange" v-if="option.controlType=='theRadio'">
                            <div class="creditLabel">{{option.parameterName}}</div>
                            <Radio :disabled="!routerParams.firstTrail || !isCheck" class="creditRadio" v-for="item in getDicData(option.dataDicId)" :label="item.value">
                                {{item.title}}
                            </Radio>
                        </RadioGroup>
                    </Row>
                </div>
            </Panel>
            <Panel class="creditCardBox"  name="4" v-show="fraudDetailDataList && fraudDetailDataList.length > 0">
                反欺诈反馈明细
                <div slot="content">
                    <Table :columns="fraudDetailColumns" :data="fraudDetailDataList" border ref="fraudDetailTable" closeable="false ">
                        <template slot-scope="{ row, index }" slot="action">
                            <a v-if="isCheck" @click="removeFraudRecord(row)">删除</a>
                        </template>
                    </Table>
                </div>
            </Panel>
            <Panel class="creditCardBox" name="5">
                信贷报告
                <div slot="content">
                    <Row class="recordHistory" v-for="record in recordHisData" v-if="isCheck || holiday || isLung">
                        <Icon type="ios-contact" class="icon" :size="70"/>
                        <Card :bordered="false" class="recordHistoryMsg" :style="record.style">
                            <h3 slot="title">{{record.title}}</h3>
                            <p>{{record.content}}</p>
                        </Card>
                    </Row>
                    <Row v-if="isCheck">
                        <Form :model="suggestData" :label-width="80" class="suggestForm" ref="suggestForm">
                            <FormItem label="审批建议" prop="approveSuggest" class="suggestSelect">
                                <div style="float: left;width:220px">
                                    <i-select v-show="isCheck" class="formSelect" v-model="suggestData.approveSuggest" @on-select="suggestSelected" @on-change="getSuggestReasonDic(true)" >
                                        <i-option v-for="item in approveSuggestDic" :key="item.title" :value="item.value">{{item.title}}</i-option>
                                    </i-select>
                                </div>
                                <div style="float: left;padding-left: 30px;" v-show="this.isCheck&&this.remindShowBo">添加共借人</div>
                                <div style="float: left;padding-left: 30px;" v-show="this.isCheck&&this.remindShowGu">添加担保人</div>
                            </FormItem>

                            <FormItem label="原因" prop="approveReason" class="suggestSelect displayItem" ref="reasonItem"
                                      v-show="reasonVisible">
                                <i-select class="formSelect" ref="reasonSelect" v-model="suggestData.approveReason" :multiple="reasonSelectMultiple">
                                    <i-option v-for="item in currentReasonDic" :value="item.value">{{item.title}}</i-option>
                                </i-select>
                            </FormItem>
                            <FormItem label="家访是否完成" prop="status" class="visitSelect displayItem" ref="visitItem"
                                      v-if="visitData.status=='done'" >
                                <i-select class="formSelect" v-model="visitData.status" disabled>
                                    <i-option v-for="item in visitStatusDic" :value="item.value">{{item.title}}</i-option>
                                </i-select>
                                <Button type="primary" ghost @click="showVisitLevel" class="visitLevel" v-show="visitData.status=='done'">质量评分表</Button>
                            </FormItem>
                            <FormItem prop="approveMessage"  ref="remarkItem" v-show="remarkVisible"
                                      class="displayItem" style="margin-top: -26px;">
                                <Input type="textarea" v-model="suggestData.approveMessage"
                                       :rows="2"
                                       class="msgTextarea"
                                       :placeholder="'请输入'+formRemarkTitle" maxlength="20"/>
                            </FormItem>
                            <div style="margin-left: 620px;margin-top: -22px;">
                            <i-select v-model="suggestTemplateId" class="templateSelect" v-if="isCheck"
                                      clearable
                                      @on-clear="clearSelectTemplate"
                                      @on-change="templateChange"
                            >
                                <i-option v-for="item in suggestTemplateData" :value="item.templateContent">{{item.templateName}}</i-option>
                            </i-select>
                            <Button @click="showRecord" type="error">录音记录</Button>
                            </div>
                            <FormItem prop="approveRemark" >
                                <Input type="textarea" v-model="suggestData.approveRemark"
                                       :rows="6"
                                       class="remarkTextarea"
                                       @on-change="setRemindRemark"
                                        style="width: 768px"
                                       placeholder="请输入信贷分析报告" maxlength="512" />
                                <Row style="margin-left: 10px">
                                    <Button class="tailButton normalButton"  size="small" @click="saveApprove(false)">暂存</Button>
                                    <Button class="tailButton normalButton" size="small" @click="submitApprove">提交</Button>
                                    <Button class="tailButton cheatButton" icon="md-add" size="small" @click="discoverFraud">发现欺诈</Button>
                                    <Button class="tailButton cheatButton" icon="md-return-right" size="small" @click="emitAntiFraud">手工触发反欺诈</Button>
                                </Row>
                            </FormItem>
                            <Spin fix size="large" v-if="submitApproveLoading"></Spin>
                        </Form>
                    </Row>
                </div>
            </Panel>
        </Collapse>
        <div v-if="isCheck">
            <Modal title="家访质量评分表"
                   v-model="visitLevelModalVisible"
                   :width="300"
                   :mask-closable='false'
            >
                <Form :modal="visitData"  :label-width="100" :disabled="!routerParams.firstTrail">
                    <FormItem prop="visitDoneLevel" label="家访目标完程度" >
                        <InputNumber :min="0" :max="5" v-model="visitData.visitDoneLevel" />
                    </FormItem>
                    <FormItem prop="visitCarefulLevel" label="走访细致程度">
                        <InputNumber :min="0" :max="5"  v-model="visitData.visitCarefulLevel" />
                    </FormItem>
                    <FormItem prop="visitReportLevel" label="报告撰写质量" >
                        <InputNumber :min="0" :max="5" v-model="visitData.visitReportLevel" />
                    </FormItem>
                    <FormItem prop="visitFileLevel" label="资料收集质量" >
                        <InputNumber :min="0" :max="5" v-model="visitData.visitFileLevel" />
                    </FormItem>
                    <FormItem prop="visitGrade" label="总分">
                        <InputNumber readonly v-model="visitData.visitGrade" />
                    </FormItem>
                    <FormItem prop="visitSuggest" label="意见" >
                        <Input type="textarea" v-model="visitData.visitSuggest" />
                    </FormItem>
                </Form>
                <div slot="footer" v-show="routerParams.firstTrail">
                    <Button type="primary" size="small" @click="saveVisitLevel" >保存</Button>
                    {{visitGradeSum}}
                </div>
            </Modal>
        </div>

        <div>
            <Modal title="录音记录" v-model="recording" footer-hide :width="1200" :styles="{top: '100px'}">
                <Row>
                    <Table border :columns="recordingColums" :data="recordingList">
                        <template slot-scope="{ row, index }" slot="custRelation">
                            <span>{{setDictTitleByType("custRelation",row.custRelation)}}电话记录</span>
                        </template>
                        <template slot-scope="{ row, index }" slot="communicatTime">
                            <span>{{row.communicatTime}}秒</span>
                        </template>
                        <template slot-scope="{ row, index }" slot="recordId">
                            <Button style="margin-right:5px" type="primary" icon="ios-play" size="small" @click="">播放
                            </Button>
                        </template>
                        <template slot-scope="{ row, index }" slot="recordText">
                            <Button style="margin-right:5px" type="primary" icon="ios-paper" size="small" @click="">阅读
                            </Button>
                        </template>
                    </Table>
                </Row>
            </Modal>
        </div>
        <!-- callStep:22 调用步骤常规审批固定值 标识 案件初审疑似欺诈 -->
        <tortoise-fraud-push v-model="fraudModalVisible" :apply-no="applyNo" :call-step="22" @onClose="cancelDiscoverFraud"/>
    </div>
</template>

<script>
    import {
        queryRemindListByApplyNo,
        queryCustSummaryInfoApplyNo,
        cancelRemindtById,
        queryRecordListByApplyNo
    } from "@/projects/afs-core-business/api/afs-case/approve/loanAnaylyze";
    import {
        getByTypes
    } from "_p/basic/api/admin/datadic";
    import {getDictDataByType} from "../../../../../../basic/api/admin/datadic";
    import {listTemplateByCurrentUser} from "../../../../../api/afs-case/credit-template/creditTemplate";
    import {
        queryApprove,
        saveApprove,
        submitApprove,
        querySomeApprove,
        getFlowCmd
    } from "../../../../../api/afs-case/approve/approveTask";
    import {
        handInvokeAntiFraud, listAntiFraudPush, removeFraudRecord,
    } from "../../../../../api/afs-case/tortoise/tortoise";
    import {queryVisitLevel,saveVisitLevel} from "../../../../../api/afs-case/approve-visit/approve-visit-level";
    import {listCreditOptionInfos} from "../../../../../api/afs-case/credit-option/creditOptionInfo";
    import {listHistoryContent} from "../../../../../api/afs-case/approve/loanAnaylyze";
    import TortoiseFraudPush from "../../tortoise/tortoise-fraud-push";
    export default {
        name: "loan-analyze",
        components: {TortoiseFraudPush},
        props: {
            applyNo: {
                required: false,
                default:()=>{
                    return '';
                }
            },
            stageId:{
                type:[String,Number],
                default:''
            },
            isCheck: {
                type: Boolean
            },
            tabName:{
                type:String

            },
            isFire: {
                type: Boolean
            },
            isLung: {
                type: Boolean
            },
            businessStateIn: {
                type: String,
                default: ""
            },
        },
        data:function () {
            return {
                remindShowBo:false,
                remindShowGu:false,
                applyNumber:'',
                values:["1","2","3","4","5","6","7","8"],
                recording:false,
                dicKeys: [
                    "msgType","custRelation","sex","maritalStatus","custRelation"
                ],
                dataDic:{},
                remindColums:[
                    {title: "操作",key: "action",minWidth: 100,align: "center",slot:"action"},
                    {title: "留言类型",key: "remindType",minWidth: 100,align: "center",slot:"remindType"},
                    {title: "处理人",key: "disposeUser",minWidth: 100,align: "center"},
                    {title: "处理时间",key: "disposeTime",minWidth: 100,align: "center"},
                    {title: "处理意见",key: "remindContent",minWidth: 100,align: "left"}
                ],
                remindList:[],
                custInfo:{
                    custInfoList:[]
                },
                custInfoColums:[
                    {title: "与主借人关系",key: "custRelation",minWidth: 100,align: "center",slot:"custRelation"},
                    {title: "姓名",key: "custName",minWidth: 100,align: "center"},
                    {title: "性别",key: "sex",minWidth: 100,align: "center",slot:"sex"},
                    {title: "年龄",key: "age",minWidth: 100,align: "center"},
                    {title: "婚姻",key: "maritalStatus",minWidth: 100,align: "center",slot:"maritalStatus"},
                    {title: "居住地",key: "livingAddress",minWidth: 100,align: "center"},
                    {title: "工作地",key: "workAddress",minWidth: 100,align: "center"},
                    {title: "工作单位",key: "unitName",minWidth: 100,align: "center"},
                    {title: "购车地",key: "purchaseAddress",minWidth: 100,align: "center"},
                ],
                recordingColums:[
                    {title: "  ",key: "custRelation",minWidth: 100,align: "center",slot:"custRelation"},
                    {title: "坐席姓名",key: "userName",minWidth: 100,align: "center"},
                    {title: "客户姓名",key: "custName",minWidth: 100,align: "center"},
                    {title: "通讯时长",key: "communicatTime",minWidth: 100,align: "center",slot:"communicatTime"},
                    {title: "被叫号码",key: "phone",minWidth: 100,align: "center"},
                    {title: "开始时间",key: "callTime",minWidth: 150,align: "center"},
                    {title: "挂机时间",key: "endTime",minWidth: 150,align: "center"},
                    {title: "电话录音",key: "recordId",minWidth: 100,align: "center",slot:"recordId"},
                    {title: "录音文本",key: "recordText",minWidth: 100,align: "center",slot:"recordText"},
                ],
                recordingList:[],
                creditOptions:[],
                creditData:[],
                creditDataDicKeys:'',
                suggestTemplateId:'',
                suggestTemplateData:[],
                recordHisData:[],
                suggestData:{},
                approveSuggestDicKey:'approveSuggest',
                approveSuggestDic:[],
                currentReasonDic:[],
                visitStatusDicKey:'visitStatus',
                visitStatusDic:[],
                formRemarkTitle:'',
                visitData:{},
                change:false,
                visitLevelModalVisible:false,
                reasonVisible:false,
                remarkVisible:false,
                submitLoading:false,
                submitApproveLoading:false,
                reasonSelectMultiple:true,
                routerParams:{},
                holiday: false,
                businessStateInList: [
                    "approved",
                    "reject",
                    "repeal",
                    "conditionalApproval",
                    "cancelConditional"
                ],
                suggestConst: {
                    check: {
                        title: "建议核准",
                        val: "suggestCheck"
                    },
                    condition: {
                        title: "建议附条件核准",
                        val:"suggestCondition"
                    },
                    reject: {
                        title: "建议拒绝",
                        val:"suggestReject"
                    },
                    visit: {
                        title: "建议家访",
                        val:"suggestVisit"
                    },
                    cancel: {
                        title: "撤销",
                        val:"suggestCancel"
                    },
                    rejectFinal: {
                        title: "拒绝",
                        val:"suggestRejectF"
                    },
                    checkFinal: {
                        title: "核准",
                        val:"suggestCheckF"
                    },
                    conditionFinal: {
                        title: "附条件核准",
                        val:"suggestConditionF"
                    },
                    sendBack:{
                        title:"退回",
                        val:"sendBack"
                    },
                    sendBackToDealer:{
                        title: "退回至经销商",
                        val: "sendBackToDealer"
                    },
                    reformist:{
                        title:"改派",
                        val: "suggestReformist"
                    }
                },
                fraudModalVisible:false,
                fraudModalLoading:false,
                fraudDetailColumns:[
                    {title: "反馈时间",key: "operateDate",align: "center"},
                    {title: "反馈节点",key: "callStepDesc",align: "center"},
                    {title: "反馈人",key: "operateStaffName",align: "center"},
                    {title: "状态",key: "pushResult",align: "center"},
                    {title: "欺诈表现",key: "fraudType",align: "center"},
                    {title: "经销商参与",key: "dealerJoin",align: "center"},
                    {title: "疑似欺诈案件详情",key: "detailMessage",minWidth: 500,align: "center"},
                    {title: "操作",key: "action",minWidth: 80,align: "center",slot:"action"}
                ],
                fraudDetailDataList:[],
                initialized: false,

            }
        },
        methods: {
            setRemindRemark() {
                this.$emit('on-set-approve', this.suggestData);
            },
            showRecord() {
                this.loadRecordList();
                this.recording = true;
            },
            getDic(v) {
                let dic = []
                switch (v) {
                    case "msgType":
                        dic = this.dataDic.msgType;
                        break;
                    case "custRelation":
                        dic = this.dataDic.custRelation;
                        break;
                    case "sex":
                        dic = this.dataDic.sex;
                        break;
                    case "maritalStatus":
                        dic = this.dataDic.maritalStatus;
                        break;
                    default:
                }
                return dic;
            },
            setDictTitleByType(v1, v2) {
                let dic = {}
                if (!this.getDic(v1)) return '';
                this.getDic(v1).forEach(column => {
                    if (column.value === v2) {
                        dic = column;
                    } else {
                        if(v1=='custRelation'){
                            if (!v2) {
                                dic = {
                                    value: '02',
                                    title: '主借人(本人)'
                                }
                            }
                        }
                    }
                });
                return dic.title;
            },
            initDataDic() {
                let self = this;
                getByTypes(this.dicKeys).then(res => {
                    if (res.code === "0000" && res.data) {
                        self.dataDic = res.data;
                    }
                });
            },
            changeAddition(val) {
                this.change = true;
                this.checkCondition();
            },
            queryRemind() {
                let params = {
                    applyNo: this.applyNumber,
                    useScene: 'approve'
                }

                queryRemindListByApplyNo(params).then(res => {
                    let  remindBo=false;
                    let  remindGu=false;
                    if (res.code === "0000") {
                        res.data.forEach(function (re) {
                            if(re.remindType==="reasonAdd"){
                                if(re.remindReason.length>0){
                                    let reasons=re.remindReason.replace("[","").replace("]","").split(",");
                                    reasons.forEach(function (e) {
                                       if(e=="\"0\""){
                                           remindBo=true;
                                       }
                                       if(e=="\"1\""){
                                           remindGu=true;
                                       }
                                    })
                                }
                            }
                        })
                        this.remindList = res.data;
                    }
                    this.remindShowBo=remindBo;
                    this.remindShowGu=remindGu;
                });
            },
            initInfo() {
                let params = {
                    applyNo: this.applyNumber
                }
                this.queryRemind()
                queryCustSummaryInfoApplyNo(params).then(res => {
                    if (res.code === "0000") {
                        this.custInfo = res.data;
                    }
                });
            },
            init() {
                this.initDataDic();
                this.initInfo();
                this.getSuggestDic();;
                this.queryCreditTemplate();
                this.initCreditOption();
                this.queryVisitLevel();
                this.queryVisitStatus();
                this.initFraudPushData();
                this.querySomeApprove();
                this.queryApprove();
                this.initCheckBusinessStateInList();
            },
            initCheckBusinessStateInList() {
                this.businessStateInList.forEach(list =>{
                    if (list === this.businessStateIn) {
                        this.holiday = true
                    }
                })
            },
            loadRecordList() {
                let params = {
                    applyNo: this.applyNumber
                }
                queryRecordListByApplyNo(params).then(res => {
                    if (res.code === "0000") {
                        this.recordingList = res.data;
                    }
                });
            },
            cancelRemind(v) {
                this.$Modal.confirm({
                    title: "撤销留言",
                    content: "确认撤销当前留言?",
                    onOk: () => {
                        let params = {
                            remindId: v.id
                        }
                        cancelRemindtById(params).then(res => {
                            if (res.code === "0000") {
                                if (res.msg === "success") {
                                    params = {
                                        applyNo: this.applyNumber,
                                        useScene: 'approve'
                                    }
                                    queryRemindListByApplyNo(params).then(result => {
                                        if (result.code === "0000") {
                                            this.remindList = result.data;
                                        }
                                    });
                                    this.$Message['success']({
                                        background: true,
                                        content: '留言撤销成功'
                                    });
                                } else {
                                    this.$Message['error']({
                                        background: true,
                                        content: '留言撤销失败'
                                    });
                                }
                            }
                        });
                    }
                })
            },
            getDicData(dicKey) {
                if (this.creditDataDicKeys.indexOf(dicKey) == -1) {
                    getDictDataByType(dicKey).then(res => {
                        this.creditData.push({
                            key: dicKey,
                            dataList: res.data
                        });
                    })
                    this.creditDataDicKeys += "[" + dicKey + "]";
                }
                ;
                let retData = {};
                this.creditData.forEach(data => {
                    if (dicKey == data.key) {
                        retData = data.dataList;
                    }
                })
                return retData;
            },
            afterRadioChange(val) {
            },
            clearSelectTemplate() {
                this.suggestData.approveRemark = '';
                this.setRemindRemark();
            },
            templateChange(val) {
                this.suggestData.approveRemark = val;
                this.setRemindRemark();
            },
            getSuggestDic() {
                let allCmdDic = [];
                getDictDataByType(this.approveSuggestDicKey).then(res => {
                    allCmdDic = res.data;
                }).then(() => {
                    if(this.stageId && this.isCheck) {
                        getFlowCmd({stageId: this.stageId}).then(res => {
                            this.approveSuggestDic = [];
                            let flowCmdSet = res.data;
                            flowCmdSet.forEach(flowCmd => {
                                allCmdDic.forEach(dic => {
                                    if (dic.value == flowCmd) {
                                        this.approveSuggestDic.push(dic);
                                    }
                                });
                            });
                        });
                    }
                })
            },
            getDicCmd(){
                // 暂时废弃，可操作命令通过流程引擎获取，再匹配系统字典
                getDictDataByType(this.approveSuggestDicKey).then(res => {
                    if (res.code == '0000') {
                        // 默认复审
                        let suggestKey = [
                            this.suggestConst.check,
                            this.suggestConst.condition,
                            this.suggestConst.reject,
                            this.suggestConst.cancel
                        ];
                        // 只有一个审核节点，即是初审，也是终审
                        if (this.routerParams.firstTrail && this.routerParams.lastTrail) {
                            suggestKey = [
                                this.suggestConst.checkFinal,
                                this.suggestConst.conditionFinal,
                                this.suggestConst.rejectFinal,
                                this.suggestConst.visit,
                                this.suggestConst.cancel
                            ]
                            // 终审
                        } else if (this.routerParams.lastTrail) {
                            suggestKey = [
                                this.suggestConst.checkFinal,
                                this.suggestConst.conditionFinal,
                                this.suggestConst.rejectFinal,
                                this.suggestConst.cancel
                            ]
                            // 初审
                        } else if (this.routerParams.firstTrail) {
                            suggestKey = [
                                this.suggestConst.check,
                                this.suggestConst.condition,
                                this.suggestConst.reject,
                                this.suggestConst.visit,
                                this.suggestConst.cancel
                            ]
                        }
                        this.approveSuggestDic = [];
                        suggestKey.forEach(suggestConst => {
                            res.data.forEach(suggest => {
                                if (suggestConst.val == suggest.value) {
                                    this.approveSuggestDic.push(suggest);
                                }
                            })
                        })
                    }
                })
            },
            suggestSelected(val) {
                this.suggestData.approveSuggestName = val.label;
            },
            getSuggestReasonDic(clear) {
                if (this.suggestData && this.suggestData.approveSuggest) {
                    getDictDataByType(this.suggestData.approveSuggest).then(res => {
                        if (res.code == "0000") {
                            this.currentReasonDic =[];
                            if(this.suggestData.approveSuggest == "suggestRejectF"){
                                res.data.forEach(dic=>{
                                    if(dic.value != '21'){ // 排除 系统自动处理的拒绝原因
                                        this.currentReasonDic.push(dic);
                                    }
                                })
                            }else{
                                this.currentReasonDic = res.data || [];
                            }
                        }
                    });
                    if (clear) {
                        if (this.suggestData) {
                            this.suggestData.approveReason = "";
                            this.suggestData.approveMessage = "";
                            this.$refs.reasonSelect.reset();
                        }
                    }
                    // 审批原因
                    if (this.suggestData.approveSuggest == this.suggestConst.check.val
                        || this.suggestData.approveSuggest == this.suggestConst.checkFinal.val
                        || this.suggestData.approveSuggest == this.suggestConst.cancel.val
                        || this.suggestData.approveSuggest == this.suggestConst.reject.val) {
                        this.reasonVisible = false;
                    } else {
                        this.reasonVisible = true;
                    }
                    // 审批留言
                    if (this.suggestData.approveSuggest == this.suggestConst.condition.val
                        || this.suggestData.approveSuggest == this.suggestConst.conditionFinal.val) {
                        this.remarkVisible = true;
                        this.formRemarkTitle = '留言';
                        this.reasonSelectMultiple = false;
                    } else if (this.suggestData.approveSuggest == this.suggestConst.visit.val) {
                        this.remarkVisible = true;
                        this.formRemarkTitle = '家访需求';
                        this.reasonSelectMultiple = true;
                    } else {
                        this.remarkVisible = false;
                        this.reasonSelectMultiple = true;
                    }
                    if (this.suggestData.approveSuggest == this.suggestConst.rejectFinal.val) {
                        this.reasonSelectMultiple = false;
                    }
                }
            },
            showVisitLevel() {
                this.visitLevelModalVisible = true;
            },
            queryCreditTemplate() {
                listTemplateByCurrentUser({}).then(res => {
                    if (res.code == '0000') {
                        this.suggestTemplateData = res.data;
                    }
                })
            },
            initRecordHistory(hasRemainData) {
                let params = {
                    stageId: this.stageId,
                    applyNo: this.applyNo,
                    check: this.isCheck
                };
                listHistoryContent(params).then(res => {
                    if (res.code == '0000') {
                        this.recordHisData = res.data.taskHistories || [];
                        let lastNormalRecord = res.data.beforeReformistContent || {}; // 上一岗非改派审批操作
                        let lastOprIsReformist = res.data.lastOprIsReformist;
                        this.recordHisData.forEach(record => {
                            if (record.approveSuggest != this.suggestConst.reformist.val) {
                                let color;
                                if (record.approveSuggest == this.suggestConst.condition.val
                                    || record.approveSuggest == this.suggestConst.conditionFinal.val) {
                                    color = "#00FFFF";
                                } else if (record.approveSuggest == this.suggestConst.reject.val
                                    || record.approveSuggest == this.suggestConst.rejectFinal.val) {
                                    color = "#EE8D8F";
                                } else if (record.approveSuggest == this.suggestConst.check.val
                                    || record.approveSuggest == this.suggestConst.checkFinal.val) {
                                    color = "#86F3AF";
                                }
                                record.style = {
                                    backgroundColor: color
                                };
                            }
                        });
                        // 上一岗位为附条件核准时，带入审批原因,审批建议默认置为附条件核准
                        if (this.isCheck && !hasRemainData) {
                            if (lastOprIsReformist) {
                                this.suggestData.approveMessage = lastNormalRecord.approveMessage;
                                this.suggestData.approveSuggest = lastNormalRecord.approveSuggest;
                                this.suggestData.approveReason = lastNormalRecord.approveReason ? lastNormalRecord.approveReason.split(",") : "";
                                this.suggestData.approveRemark = lastNormalRecord.approveRemark;
                                this.getSuggestReasonDic(false);
                            } else if (this.recordHisData && this.recordHisData.length > 0
                                && this.recordHisData[0].approveSuggest == this.suggestConst.condition.val) {
                                if (this.routerParams.lastTrail) {
                                    this.suggestData.approveSuggest = this.suggestConst.conditionFinal.val;
                                } else {
                                    this.suggestData.approveSuggest = this.suggestConst.condition.val;
                                }
                                this.suggestData.approveReason = this.recordHisData[0].approveReason.split(",");
                                this.suggestData.approveMessage = this.recordHisData[0].approveMessage;
                                this.suggestData.approveRemark = this.recordHisData[0].content;
                                this.getSuggestReasonDic(false);

                            }
                        }
                    }
                })
            },
            initCreditOption() {
                listCreditOptionInfos({
                    applyNo: this.applyNo,
                    showBusinessType: this.routerParams.businessType,
                    checkPage: this.isCheck
                }).then(res => {
                    if (res.code == "0000") {
                        this.creditOptions = res.data;
                    }
                })
            },
            saveVisitLevel() {
                this.submitLoading = true;
                saveVisitLevel(this.visitData).then(res => {
                    if (res.code == "0000") {
                        this.queryVisitLevel();
                    }
                    this.$Message.info("保存成功");
                    this.visitLevelModalVisible = false;
                }).finally(() => {
                    this.submitLoading = false;
                })
            },
            queryVisitLevel() {
                if (!this.visitData.applyNo) {
                    this.visitData.applyNo = this.applyNo;
                }
                if (!this.visitData.stageId) {
                    this.visitData.stageId = this.stageId;
                }
                queryVisitLevel(this.visitData).then(res => {
                    if (res.code == "0000" && res.data) {
                        this.visitData = res.data;
                    }
                })
            },
            saveApprove(silently) {
                this.suggestData.approveReason = this.suggestData.approveReason
                    ? this.suggestData.approveReason.toString()
                    : "";
                let params = {
                    creditOptionInfos: this.creditOptions,
                    approveRecord: this.suggestData
                };
                this.submitApproveLoading = !silently;
                saveApprove(params).then(res => {
                    if (res.code == "0000") {
                        if(!silently) {
                            this.$Message.info("保存成功!")
                        }
                        this.creditOptions = res.data.creditOptionInfos;
                        this.suggestData = res.data.approveRecord;
                        if (this.suggestData.approveReason) {
                            this.suggestData.approveReason = this.suggestData.approveReason.split(',');
                        }
                    }
                }).finally(() => {
                    this.submitApproveLoading = false;
                })
            },
            submitApprove() {
                if ( !(this.suggestData.approveSuggest == this.suggestConst.cancel.val)){
                    if (this.creditOptions.length > 0) {
                        for (let i = 0; i < this.creditOptions.length; i++) {
                            if (!this.creditOptions[i].riskContent) {
                                this.$Message.warning("信贷选项[ <span style='color: red'>" + this.creditOptions[i].parameterName + "</span> ]未选择，无法提交");
                                return;
                            }
                        }
                    }
                }
                if (this.routerParams.lastTrail){
                    if ( this.suggestData.approveSuggest === this.suggestConst.rejectFinal.val) {
                        if (!this.suggestData.approveReason) {
                            this.$Message.warning("请选择原因");
                            return;
                        }
                    }
                }
                if (this.routerParams.firstTrail && this.routerParams.lastTrail) {
                    if (!this.suggestData.approveRemark){
                        this.$Message.warning("请填写信贷分析报告");
                        return;
                    }
                }
                if (this.routerParams.firstTrail && !this.routerParams.lastTrail) {
                    if ( this.suggestData.approveSuggest === this.suggestConst.condition.val){
                        if (!this.suggestData.approveReason){
                            this.$Message.warning("请选择原因");
                            return;
                        }
                    }
                }
                if (!this.routerParams.lastTrail) {
                    if (!this.suggestData.approveRemark){
                        this.$Message.warning("请填写信贷分析报告");
                        return;
                    }
                }
                if (!this.suggestData.approveSuggest) {
                    this.$Message.warning("请选择审批建议");
                    return;
                }
                if (this.suggestData.approveSuggest == this.suggestConst.visit.val) {
                    alert("等待开发...");
                    return false;
                }
                if (this.suggestData.approveSuggest == this.suggestConst.cancel.val
                    && (!this.suggestData.approveRemark || !this.suggestData.approveRemark.trim())) {
                    this.$Message.warning("撤销备注不可为空");
                    return false;
                }
                if (this.suggestData.approveSuggest != this.suggestConst.cancel.val && !this.routerParams.firstTrail) {
                    if (this.recordHisData.length > 0 && this.recordHisData[0].approveSuggest != this.suggestConst.sendBack.val
                        && this.recordHisData[0].approveSuggest != this.suggestConst.sendBackToDealer.val) {
                        let lastApproveSuggest = this.recordHisData[0].approveSuggest;
                        let currentApproveSuggest = this.suggestData.approveSuggest;
                        if (this.routerParams.lastTrail) {
                            if ((lastApproveSuggest == this.suggestConst.condition.val
                                && currentApproveSuggest != this.suggestConst.conditionFinal.val)
                                || (lastApproveSuggest == this.suggestConst.check.val
                                    && currentApproveSuggest != this.suggestConst.checkFinal.val)
                                || (lastApproveSuggest == this.suggestConst.reject.val
                                    && currentApproveSuggest != this.suggestConst.rejectFinal.val)) {
                                this.$Message.warning("审批建议必须与上一岗位审核意见保持一致.");
                                return false;
                            }
                        } else if (lastApproveSuggest != currentApproveSuggest) {
                            this.$Message.warning("审批建议必须与上一岗位审核意见保持一致.");
                            return false;
                        }
                    }
                }
                this.$Modal.confirm({
                    title: "确认",
                    content: "确认提交?",
                    onOk: () => {
                        this.suggestData.approveReason = this.suggestData.approveReason ? this.suggestData.approveReason.toString() : "";
                        let params = {
                            creditOptionInfos: this.creditOptions,
                            approveRecord: this.suggestData
                        };
                        this.submitApproveLoading = true;
                        submitApprove(params).then(res => {
                            if (res.code == "0000") {
                                this.$emit("whenClose");
                                this.$Message.info("提交成功!");
                                window.close();
                            }
                        }).finally(() => {
                            this.submitApproveLoading = false;
                        })
                    }
                });
            },
            queryApprove() {
                let params = {
                    applyNo: this.applyNo,
                    stageId: this.stageId
                };
                let queried = false;
                queryApprove(params).then(res => {
                    if (res.code == "0000") {
                        this.suggestData = res.data || {};
                        if (res.data.queried) {
                            if (this.suggestData.approveReason) {
                                this.suggestData.approveReason = this.suggestData.approveReason.split(',');
                            }
                            this.getSuggestReasonDic(false);
                        }
                        queried = res.data.queried;
                    }
                }).then(()=>{
                    this.initRecordHistory(queried);
                }).then(()=>{
                    this.checkCondition();
                }).then(()=>{
                    if(this.suggestData.approveRemark){
                        this.setRemindRemark();
                    }
                });
            },
            checkCondition(){
                if(this.change) {
                    if (this.suggestData.approveSuggest != this.suggestConst.conditionFinal.val
                        && this.suggestData.approveSuggest != this.suggestConst.condition.val) {
                        if (this.routerParams.lastTrail) {
                            this.suggestData.approveSuggest = this.suggestConst.conditionFinal.val;
                        } else {
                            this.suggestData.approveSuggest = this.suggestConst.condition.val;
                        }
                        this.getSuggestReasonDic(true);
                    }
                    this.saveApprove(true);
                }
            },
            querySomeApprove() {
                if (this.isFire){
                    let params = {
                        applyNo: this.applyNo
                    };
                    querySomeApprove(params).then(res => {
                        if (res.code == "0000") {
                            this.suggestData = res.data ;
                            if (res.data) {
                                if (this.suggestData.approveReason) {
                                    this.suggestData.approveReason = this.suggestData.approveReason.split(',');
                                }
                                if (this.suggestData.approveSuggest) {
                                    getByTypes('approveSuggest').then(res => {
                                        if (res.code == "0000") {
                                            res.data.approveSuggest.forEach(suggest => {
                                                if (suggest.value == this.suggestData.approveSuggest) {
                                                    this.suggestData.approveSuggest = suggest.title;
                                                }
                                            })
                                        }
                                    });
                                }
                            }
                            this.getSuggestReasonDic(false);
                        }
                    });
                }
            },
            queryVisitStatus() {
                getDictDataByType(this.visitStatusDicKey).then(res => {
                    if (res.code == "0000") {
                        this.visitStatusDic = res.data;
                    }
                })
            },
            discoverFraud() {
                this.fraudModalVisible = true;
            },
            cancelDiscoverFraud(doFlush) {
                this.fraudModalVisible = false;
                if(doFlush) {
                    this.initFraudPushData();
                }
            },
            emitAntiFraud() {
                this.$Modal.confirm({
                    title: "反欺诈触发",
                    content: "您确定要手工触发反欺诈吗?",
                    onOk: () => {
                        let params = {
                            applyNo: this.applyNo,
                            callStep: "21" // 常规审批时固定值，标识 案件初审手工核查
                        };
                        this.submitApproveLoading = true;
                        handInvokeAntiFraud(params).then(res => {
                            if (res.code == "0000") {
                                this.$Message.info("操作成功!");
                            }
                        }).finally(() => {
                            this.submitApproveLoading = false;
                        });
                    }
                });
            },
            initFraudPushData() {
                listAntiFraudPush({
                    applyNo: this.applyNumber
                }).then(res => {
                    if (res.code == "0000") {
                        this.fraudDetailDataList = res.data;
                    }
                })
            },
            removeFraudRecord(row){
                this.$Modal.confirm({
                    title: "删除",
                    content: "您确定要删除当前反欺诈信息吗?",
                    onOk: () => {
                        this.$Spin.show();
                        removeFraudRecord(row.id).then(res=>{
                            this.$Message.info("操作成功!");
                            this.initFraudPushData();
                        }).finally(() => {
                            this.$Spin.hide();
                        });
                    }
                });

            }

        },
        mounted() {

        },
        created() {
            this.applyNumber = this.applyNo!=''?this.applyNo:this.afs.getPageParams(this).applyNo;
            this.suggestData.applyNo = this.applyNo;
            this.suggestData.stageId = this.stageId;
            this.routerParams = this.afs.getPageParams(this);
            this.isCheck=this.routerParams.isCheck;
            this.isFire=this.routerParams.isFire;
            this.stageId=this.routerParams.stageId;
            this.applyNo= this.routerParams.applyNo;

            this.init();
        },
       /* watch:{
            tabName(val){
                // 仅加载一次，tab页切换点击不再加载
               if(val=='name4' && !this.initialized){
                    this.init();
                    this.initialized = true;
               }
            }
        },*/
        computed:{

            visitGradeSum : function(){
                if(this.visitData) {
                    this.visitData.visitGrade = (this.visitData.visitCarefulLevel
                        + this.visitData.visitDoneLevel
                        + this.visitData.visitReportLevel
                        + this.visitData.visitFileLevel) || 0;
                }
                return '';
            }
        }
    }
</script>

<style scoped>

</style>
